using UnityEngine;
using LS.UI;
using Unity.VisualScripting;

namespace LS.VisualScripting
{
    public class OpenUIForm_FormId : UIUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput UIFormId { get; set; }
        
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput UserData { get; set; }
        
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput SerialId { get; set; }
        protected override void Definition()
        {
            base.Definition();
            UIFormId = ValueInput<int>(nameof(UIFormId), 0);
            UserData = ValueInput<object>(nameof(UserData), null);
            SerialId = ValueOutput<int>(nameof(SerialId));
            Requirement(UIFormId, Input);
            Requirement(UserData, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            int formId = flow.GetValue<int>(UIFormId);
            object userData = flow.GetValue<object>(UserData);
            int serialId = Target?.OpenUIForm(formId, userData) ?? 0;
            flow.SetValue(SerialId, serialId);
            return base.In(flow);
        }
    }
}